media: firewire: firedtv-avc: fix a buffer overflow in avc_ca_pmt()
authorDan Carpenter <dan.carpenter@oracle.com>
Mon, 7 Jun 2021 15:23:48 +0000 (17:23 +0200)
committerSalvatore Bonaccorso <carnil@debian.org>
Wed, 3 Nov 2021 14:35:31 +0000 (14:35 +0000)
commit0f04e636bc5c7d89979de6b875bbf222a9a7d455
treed9606c38e584e14db8f68fe7ffa4d76d013dd56c
parentf7a616e263fab9673fe9e1e3d119e3965144b7be
media: firewire: firedtv-avc: fix a buffer overflow in avc_ca_pmt()

Origin: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git/commit?id=de92c86f05266dbb413a317102a6c1b5de0853e8
Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2021-42739

commit 35d2969ea3c7d32aee78066b1f3cf61a0d935a4e upstream.

The bounds checking in avc_ca_pmt() is not strict enough.  It should
be checking "read_pos + 4" because it's reading 5 bytes.  If the
"es_info_length" is non-zero then it reads a 6th byte so there needs to
be an additional check for that.

I also added checks for the "write_pos".  I don't think these are
required because "read_pos" and "write_pos" are tied together so
checking one ought to be enough.  But they make the code easier to
understand for me.  The check on write_pos is:

if (write_pos + 4 >= sizeof(c->operand) - 4) {

The first "+ 4" is because we're writing 5 bytes and the last " - 4"
is to leave space for the CRC.

The other problem is that "length" can be invalid.  It comes from
"data_length" in fdtv_ca_pmt().

Cc: stable@vger.kernel.org
Reported-by: Luo Likang <luolikang@nsfocus.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Gbp-Pq: Topic bugfix/all
Gbp-Pq: Name media-firewire-firedtv-avc-fix-a-buffer-overflow-in-.patch
drivers/media/firewire/firedtv-avc.c
drivers/media/firewire/firedtv-ci.c